/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package quartz;

import java.text.ParseException;
import java.util.Date;
import org.quartz.CronTrigger;
import org.quartz.JobDataMap;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;

/**
 *
 * @author bighead
 */
public class TriggerBuilder {

    public static final String DEFAULT_TRIGGER_GROUP_NAME = "DefaultTrigggerGroup";

    public static Trigger buildSimpleTrigger(String triggerName, String triggerGroupName, Date startTime, Date endTime, long triggerInterval, JobDataMap jobDataMap) {
        SimpleTrigger trigger = new SimpleTrigger(triggerName, triggerGroupName, startTime, endTime, SimpleTrigger.REPEAT_INDEFINITELY, triggerInterval);
        trigger.setJobDataMap(jobDataMap);
        return trigger;
    }

    public static Trigger buildSimpleTrigger(String triggerName, String triggerGroupName, Date startTime, Date endTime, long triggerInterval) {
        return buildSimpleTrigger(triggerName, triggerGroupName, startTime, endTime, triggerInterval, null);
    }

    public static Trigger buildSimpleTrigger(String triggerName, String triggerGroupName, Date startTime, long triggerInterval) {
        return buildSimpleTrigger(triggerName, triggerGroupName, startTime, null, triggerInterval, null);
    }

    public static Trigger buildSimpleTrigger(String triggerName, Date startTime, long triggerInterval) {
        return buildSimpleTrigger(triggerName, DEFAULT_TRIGGER_GROUP_NAME, startTime, null, triggerInterval, null);
    }

    public static Trigger buildSimpleTrigger(String triggerName, long triggerInterval) {
        return buildSimpleTrigger(triggerName, DEFAULT_TRIGGER_GROUP_NAME, new Date(), null, triggerInterval, null);
    }

    public static Trigger buildCronTrigger(String triggerName, String triggerGroupName, Date startTime, Date endTime, String cronExpression, JobDataMap jobDataMap) throws ParseException {
        CronTrigger trigger = new CronTrigger(triggerName, triggerGroupName);
        trigger.setStartTime(startTime);
        trigger.setEndTime(endTime);
        trigger.setCronExpression(cronExpression);
        trigger.setJobDataMap(jobDataMap);
        return trigger;

    }

    public static Trigger buildCronTrigger(String triggerName, String triggerGroupName, Date startTime, Date endTime, String cronExpression) throws ParseException {
        return buildCronTrigger(triggerName, triggerGroupName, startTime, endTime, cronExpression, null);
    }

    public static Trigger buildCronTrigger(String triggerName, String triggerGroupName, Date startTime, String cronExpression) throws ParseException {
        return buildCronTrigger(triggerName, triggerGroupName, startTime, null, cronExpression, null);
    }

    public static Trigger buildCronTrigger(String triggerName, Date startTime, Date endTime, String cronExpression) throws ParseException {
        return buildCronTrigger(triggerName, DEFAULT_TRIGGER_GROUP_NAME, startTime, endTime, cronExpression, null);
    }

    public static Trigger buildCronTrigger(String triggerName, Date startTime, String cronExpression) throws ParseException {
        return buildCronTrigger(triggerName, DEFAULT_TRIGGER_GROUP_NAME, startTime, null, cronExpression, null);
    }

    public static Trigger buildCronTrigger(String triggerName, String cronExpression) throws ParseException {
        return buildCronTrigger(triggerName, DEFAULT_TRIGGER_GROUP_NAME, new Date(), null, cronExpression, null);
    }    
}
